<template>
	<view style="padding-bottom: 100rpx;" v-if="pageShow">
		<u-swiper :list="dataAll.images_text" keyName="image_text" height="380" indicator circular></u-swiper>
		<view class="mainpadding2">
			<view class="mainpadding_top ffffff radius">
				<view class="flexbetween">
					<view class="sanshier xiaohuang bold" style="font-size: 40rpx;">{{dataAll.price}}</view>
					<u-number-box button-size="36" color="#000000" bgColor="#F7F7F7" iconStyle="color: #fff"
						v-model="number"></u-number-box>
				</view>
				<view class="xiaohui main_size margin_top">{{dataAll.name}}</view>
			</view>
			<view class="mainpadding_top ffffff radius">
				<view class="titletext hei_text bold">使用门店</view>
				<view class="flexbetween xiahuaxian margin_top" v-for="item in dataAll.shopinfo" :key="item.id">
					<view class="">
						<view class="main_size xiaohei bold">{{item.name}}</view>
						<view class="xiankuan margin_top" style="width: 500rpx;">
							<text
								class="xiaohuang ershiba margin_right2">距您{{returnKmUnit(Number(item.distance))}}</text>
							<text class="xiaohui ershiba">{{item.address}}</text>
						</view>
					</view>
					<view class="daohang" @click="openmap(item)"></view>
				</view>
			</view>

		</view>
		<view class="mainpadding_top ffffff">
			<view class="textcenter titletext hei_text">商品详情</view>
			<view class="margin_top">
				<u-parse :content="dataAll.content"></u-parse>
			</view>
		</view>
		<view class="gudingdb mainpadding">
			<view class="bigbtn" @click="ljdhFn()">立即兑换</view>
		</view>
	</view>
</template>

<script>
	import {checkOpenGPSServiceByAndroid } from '@/common/openseting.js'
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				number: 1,
				lat: "",
				lng: "",
				dataAll: {},
				listid: "",
				pageShow: false,
				isgetlocation:true
			}
		},
		onLoad(options) {
			this.listid = options.id
			// #ifdef APP-PLUS
			this.getLocation()
			// #endif
			// #ifdef H5
			this.getDetail()
			// #endif
		},
		onShow() {
			if(this.isgetlocation==false){
				// #ifdef APP-PLUS
				this.getLocation()
				// #endif
				// #ifdef H5
				this.getDetail()
				// #endif
			}
		},
		methods: {
			getLocation() {
				let _this = this
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						uni.hideLoading()
						console.log(res, "获取定位成功");
						_this.lat = res.latitude
						_this.lng = res.longitude
						_this.getDetail()
					},
					fail(err) {
						uni.hideLoading()
						_this.isgetlocation = false
						checkOpenGPSServiceByAndroid()
					}
				});
			},
			getDetail() {
				httpRequest.request('/api/goodscl/goodsDetail', 'GET', {
					goods_id: this.listid,
					lat: this.lat,
					lng: this.lng,
				}).then(res => {
					this.dataAll = res.data
					this.pageShow = true
				})
			},
			ljdhFn() {
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false
				}
				let data = {
					data: [{
						goods_id: this.listid,
						number: this.number
					}],
					lat: this.lat,
					lng: this.lng
				}
				uni.navigateTo({
					url: "/pages_index/querendd?msg=" + encodeURIComponent(JSON.stringify(data))
				})
			},
			openmap(item) {
				uni.openLocation({
					latitude: Number(item.latitude), //即将传到高德或腾讯地图的终点纬度  必须是数值，字符串无效
					longitude: Number(item.longitude), //即将传到高德或腾讯地图的终点经度  必须是数值，字符串无效
					name: item.address, //即将传到高德或腾讯地图的店铺名称
					address: item.address, //即将传到高德或腾讯地图的详细地址
					scale: 18
				})
			}
		}
	}
</script>

<style>

</style>